<?php
namespace app\home\controller;

use app\common\controller\Indexbase;

class Wxtoken extends Indexbase {
    //  首页
    public function index(){
        $signature = $_GET['signature'];
        $nonce = $_GET['nonce'];
        $timestamp = $_GET['timestamp'];
        $echostr = $_GET['echostr'];
        //把这三个参数存到一个数组里面
        $tmpArr = array($timestamp,$nonce,$this->webdb['wxtoken']);
        //进行字典排序
        sort($tmpArr);
        //把数组中的元素合并成字符串，impode()函数是用来将一个数组合并成字符串的
        $tmpStr = implode($tmpArr);
        //sha1加密，调用sha1函数
        $tmpStr = sha1($tmpStr);
        //判断加密后的字符串是否和signature相等
        if($tmpStr == $signature){
            echo $echostr;
            exit;
        }
        return false;
    }

}
